package xyz.xtt.user.client.response;

import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import xyz.xtt.user.api.enums.UserStatus;

@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class UserInfoResponse {

	// @ApiModelProperty(value = "应用user_id")
	private Long appUserId;

	// @ApiModelProperty(value = "手机号")
	private String phone;

	// @ApiModelProperty(value = "手机号Bk")
	private String phoneBk;

	// @ApiModelProperty(value = "邮箱地址")
	private String email;

	// @ApiModelProperty(value = "用户状态{0：正常、1：禁用、2：注销、3、管理员}")
	private Integer status;

	// @ApiModelProperty(value = "站内昵称")
	private String nickname;

	// @ApiModelProperty(value = "头像[只包含文件名部分]")
	private String avatarUri;

	// @ApiModelProperty(value = "性别 0:男、1：女、2：未知")
	private Integer gender;

	// @ApiModelProperty(value = "注册时间")
	private LocalDateTime registerDatetime;

	// @ApiModelProperty(value = "用户姓名")
	private String userName;

	// @ApiModelProperty(value = "身份证号")
	private String idCardNo;

	// @ApiModelProperty(value = "认证状态")
	private Integer authStatus;

	// @ApiModelProperty(value = "上次认证时间")
	private Long authBefore;

	public boolean checkStatus() {
		return Objects.equals(status, UserStatus.NORMAL.getCode());
	}

	public String fieldVal(Function<UserInfoResponse, String> mapper) {
		return Optional.ofNullable(this).map(mapper).orElse("");
	}

	public boolean filterGender() {
		return Objects.equals(gender, 1) || Objects.equals(gender, 2);
	}

	public boolean checkGender() {
		return !filterGender();
	}

}
